// Scene Node Creators
// (c) jimon game studio

#ifndef JEH_JESCENENODECREATORS
#define JEH_JESCENENODECREATORS

#include "ISceneManager.h"
#include "CRootSceneNode.h"
#include "CCameraSceneNode.h"
#include "CSpriteSceneNode.h"
#include "CPivotSceneNode.h"
#include "CTextSceneNode.h"
#include "CDebugSceneNode.h"
#include "CMeshSceneNode.h"
#include "CLightSceneNode.h"

namespace je
{
	namespace scene
	{

		template <class T>
		class NodeFactoryCreator_DescRender:public ISceneManager::NodeFactoryType::BaseTypeCreator
		{
		protected:
			video::IRender * CurrentRender;
		public:
			NodeFactoryCreator_DescRender(video::IRender * Render,scene::ISceneManager * SceneManager)
				:CurrentRender(Render)
			{
			}

			ISceneNode * Create()
			{
				ISceneNode * NewCreate = NULL;
				JENEW(NewCreate, T (CurrentRender))
				return NewCreate;
			}
		};

		template <class T>
		class NodeFactoryCreator_DescRenderSceneManager:public ISceneManager::NodeFactoryType::BaseTypeCreator
		{
		protected:
			video::IRender * CurrentRender;
			scene::ISceneManager * CurrentSceneManager;
		public:
			NodeFactoryCreator_DescRenderSceneManager(video::IRender * Render,scene::ISceneManager * SceneManager)
				:CurrentRender(Render),CurrentSceneManager(SceneManager)
			{
			}
			ISceneNode * Create()
			{
				ISceneNode * NewCreate = NULL;
				JENEW(NewCreate, T (CurrentRender,CurrentSceneManager))
				return NewCreate;
			}
		};

		template<class T>
		void RegisterNodeType(ISceneManager::NodeFactoryType * Factory,video::IRender * Render,scene::ISceneManager * SceneManager,const jeStringc & Name)
		{
			ISceneManager::NodeFactoryType::BaseTypeCreator * Creator = NULL;
			JENEW(Creator,T(Render,SceneManager))
			Factory->RegisterDiscribedClass(Name,Creator);
		}

		#define ADD_NODE_FACTORY_TYPE_DR(__Name) typedef NodeFactoryCreator_DescRender< C##__Name > FactoryCreator_C##__Name ;\
											RegisterNodeType< FactoryCreator_C##__Name >(Factory,Render,SceneManager, #__Name );
		#define ADD_NODE_FACTORY_TYPE_DRSM(__Name) typedef NodeFactoryCreator_DescRenderSceneManager< C##__Name > FactoryCreator_C##__Name ;\
											RegisterNodeType< FactoryCreator_C##__Name >(Factory,Render,SceneManager, #__Name );

		void RegisterNodeTypes(ISceneManager::NodeFactoryType * Factory,video::IRender * Render,scene::ISceneManager * SceneManager)
		{
			ADD_NODE_FACTORY_TYPE_DR(RootSceneNode)
			ADD_NODE_FACTORY_TYPE_DR(CameraSceneNode)
			ADD_NODE_FACTORY_TYPE_DRSM(SpriteSceneNode)
			ADD_NODE_FACTORY_TYPE_DR(PivotSceneNode)
			ADD_NODE_FACTORY_TYPE_DRSM(TextSceneNode)
			ADD_NODE_FACTORY_TYPE_DRSM(DebugSceneNode)
			ADD_NODE_FACTORY_TYPE_DRSM(MeshSceneNode)
			ADD_NODE_FACTORY_TYPE_DRSM(LightSceneNode)
		}
	}
}

#endif
